package site.jlopen.kuscia.model.task;


import site.jlopen.kuscia.model.task.TaskInputConfig;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONException;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class JobTask {
	private static Logger logger = LoggerFactory.getLogger(JobTask.class);

	private String taskId;
	
	private String alias;
	
	private List<String> parties;
	
	private List<String> dependencies;

	private String taskInputConfig;
	
	public JobTask(String taskId, String alias) {
		super();
		this.taskId = taskId;
		this.alias = alias;
	}
	
	public JobTask addPartie(String domainId) {
		if(null == this.parties) {
			this.parties = new ArrayList<String>();
			this.parties.add(domainId);
		}
		return this;
	}
	
	public JobTask addDependencie(String dependencie) {
		if(null == this.dependencies) {
			this.dependencies = new ArrayList<String>();
			this.dependencies.add(dependencie);
		}
		return this;
	}
	
	public JobTask addConfig(TaskInputConfig config) {
		if(null == config) {
			return this;
		}
		try {
			this.taskInputConfig = JSON.toJSONString(config);
		} catch (JSONException e) {
			logger.error("配置转JSON异常：{}", e);
		}
		return this;
	}
}
